/**
 * 分成利润列表
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>分成利润</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="boxBlock"> 
        <div class="serachTop"> 
              <!-- 搜索筛选 -->
            <el-form :inline="true" :model="formInline" class="user-search"> 
              <el-form-item>
                <el-input
                  size="small"
                  v-model="formInline.userId"
                  placeholder="输入用户ID"
                  type="number"
                  clearable
                ></el-input>
              </el-form-item>  
              

              <el-form-item>
                  <el-select
                      size="small"
                      v-model="formInline.status"
                      placeholder="请选择审核状态" clearable
                    >
                      <el-option
                        v-for="type in typeData"
                        :label="type.value"
                        :value="type.key"
                        :key="type.key"
                      ></el-option>
                    </el-select>
              </el-form-item> 
           
              <el-form-item>
                <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-search"
                  @click="search"
                >
                  搜索
                </el-button>  
              </el-form-item>
            </el-form>
        </div> 
  
    <!--列表-->
    <div class="ra_box"> 
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 100%" 
      > 
        <el-table-column prop="userId" label="用户ID"> </el-table-column> 
        <el-table-column prop="execRate" label="分成比例" show-overflow-tooltip>  </el-table-column>
        <el-table-column prop="profitsAmount" label="分成金额" show-overflow-tooltip>  </el-table-column>
        <el-table-column prop="profitsTime" label="分成年月" show-overflow-tooltip>  </el-table-column>
        <el-table-column prop="returnRate" label="退款率" show-overflow-tooltip>  </el-table-column>
        <el-table-column prop="totalAmount" label="待分成总额" show-overflow-tooltip>  </el-table-column>
        <!-- <el-table-column prop="execRate" label="分成比例" show-overflow-tooltip>  </el-table-column>   -->
        <el-table-column prop="floatAmount" label="浮动分成金额" show-overflow-tooltip>  </el-table-column>   
 
        <el-table-column prop="status" label="状态" width="100">
            <template slot-scope="scope">  
                  <!-- {{ scope.row.type==0?'待审核':scope.row.type==0?'通过':'驳回' }}    -->
                <el-tag type="success" v-if="scope.row.status==1">通过</el-tag>
                <el-tag type="warning" v-if="scope.row.status==0">待审核</el-tag> 
                <el-tag type="danger" v-if="scope.row.status==2">驳回</el-tag> 
            </template> 
            <!-- (0待审核1通过2驳回) --> 
        </el-table-column>
        <el-table-column prop="auditResult" label="审核结果" show-overflow-tooltip>  </el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip> </el-table-column> 
        <el-table-column
          prop="createTime"
          label="创建时间"
          show-overflow-tooltip
        >
           <template slot-scope="scope">
              {{ timestampToTime(scope.row.createTime, 8 * 60 * 60) }}
            </template>
        </el-table-column>   
        <el-table-column
          prop="updateTime"
          label="更新时间"
          show-overflow-tooltip
        >
           <template slot-scope="scope">
              {{ timestampToTime(scope.row.createTime, 8 * 60 * 60) }}
            </template>
        </el-table-column> 
        <el-table-column
          prop="updateBy"
          label="更新者"
          show-overflow-tooltip
        > 
        </el-table-column>   
        <el-table-column align="left" label="操作" width="180" fixed="right" >
            <template slot-scope="scope">  
              <el-button size="mini"   type="success" plain @click="handleEdit(scope.row)" v-if="userInfo.userType=='00'&&scope.row.status==0">
                审核
              </el-button>   
            </template>
          </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
  </div>


  <el-dialog
      :close-on-click-modal="false"
      title="审核"
      :visible.sync="addFormVisible"
      width="40%" 
      @close="closeDialog('refundForm')"
    >
      <el-form
        :model="refundForm"
        :rules="refundrules"
        ref="refundForm"
        label-width="120px"
      >
        
        <el-form-item label="审核状态" prop="status" class="wid-9">
            <el-select
                size="small"
                v-model="refundForm.status"
                placeholder="请选择审核状态" clearable
            >
                <el-option 
                    label="通过"
                    value="1" 
                ></el-option>
                <el-option 
                    label="驳回"
                    value="2" 
                ></el-option> 
                <!-- 1通过2驳回 --> 

            </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark" class="wid-9">
          <el-input
            type="textarea"
            size="small"
            v-model.trim="refundForm.remark"
            :rows="5"
            auto-complete="off"
            placeholder="备注"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog('refundForm')">
          取消
        </el-button>
        <el-button
          size="small"
          type="primary" 
          class="title"
          @click="submitForm('refundForm')"
          >提交</el-button
        >
      </div>
    </el-dialog> 
    <codeChoose ref="codeRef" :fromType="verType" @setParam="getParam" ></codeChoose>
 
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import codeChoose from '@/components/codeChoose.vue'
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  timestampToTime,
  spStr,
} from "../../utils/util";
import {
  baseURL,
  req,
  reqJson,
  encrypt,
  decrypt,
  reqtoken,
  service,
  format,
  getUrl,
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false, 
      addFormVisible: false, 
      b: format,
      timestampToTime: timestampToTime,
      formInline: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        userId: "",
      },
      refundForm: { 
      }, 
      // rules表单验证
      refundrules: {
        status: [
          { required: true, message: "请选择状态", trigger: "blur" }, 
        ],
      },
   
      options: [],
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      userInfo:{}, 
      typeData:[
        {
          key:0,
          value:'待审核'
        },
        {
          key:1,
          value:'通过'
        },
        {
          key:2,
          value:'驳回'
        }

        // 0待审核1通过2驳回
      ], 
      verArry:[],
      verType:'',
      curItem:'', 
      userInfo: null,
      fd:'', 
      headers:'', 
      

    };
  },
  // 注册组件
  components: {
    Pagination,
    codeChoose
  },
  created() {
    this.getdata(this.formInline);
    if(this.$store.state.user){
        this.userInfo = JSON.parse(this.$store.state.user);
    }
  },
  computed: {
    ...mapGetters(["getUser"]), 
  },
  watch: {
    getUser(newVal) {
      this.userInfo = JSON.parse(newVal); 
    },
  }, 
  methods: {
    getdata(parameter) {
      let url = getUrl(parameter);  
      let objectUrl = 'admin' 
      if(this.$store.state.user){
        this.userInfo = JSON.parse(this.$store.state.user);
      }  
      if(this.userInfo.userType=='01'){ 
        objectUrl = 'photon/agentProfitsRecordList' 
      }else{ 
        objectUrl = 'admin/getAgentProfitsRecordList'
      }   

      service
        .get("/api/"+objectUrl + url, {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
 
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    handleEdit(row) {
        this.addFormVisible = true;
        this.refundForm = {
            id:row.id,
            userId:row.userId,

        } 
    }, 

    getParam(val,type){  
      this.headers = val ;
      this.editSaveAuth() 
    },  
    editSaveAuth(){  
        reqJson('post',"/api/admin/verifyProfitsRecord?id="+this.refundForm.id+'&userId='+this.refundForm.userId+'&remark='+this.refundForm.remark+'&status='+this.refundForm.status, this.refundForm, {},{
          headers:{
            ...this.headers
          }
        }).then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.$message.success(res.msg); 
            this.pageparm.currentPage = 1;
            this.getdata();
            this.closeDialog("refundForm"); 
          } else {
            this.$message({
              type: "info",
              message: res.msg,
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    submitForm(name) {
      this.$refs[name].validate((valid) => {
        if (!valid) return;
        this.loading = true;  
        if(this.userInfo&&this.userInfo.verifyApi){
          console.log(this.verArry.includes('/api/admin/verifyProfitsRecord'))
          this.verArry =  this.userInfo.verifyApi.split(',');
          if(this.verArry.includes('/api/admin/verifyProfitsRecord')){
            this.$refs.codeRef.openDialog(); 
          }else{
            this.editSaveAuth();
          }
        }else{
           this.editSaveAuth();
        } 
            // service
            // .post("/api/admin/verifyProfitsRecord?id="+this.refundForm.id+'&userId='+this.refundForm.userId+'&remark='+this.refundForm.remark+'&status='+this.refundForm.status, this.refundForm)
            // .then((res) => {
            //   this.loading = false;
            //   if (res.code == 0) {
            //     this.$message.success(res.msg); 
            //     this.pageparm.currentPage = 1;
            //     this.getdata();
            //     this.closeDialog("refundForm"); 
            //   } else {
            //     this.$message({
            //       type: "info",
            //       message: res.msg,
            //     });
            //   }
            // })
            // .catch((err) => {
            //   this.$message.error(spStr(err, "PhotonPay", ""));
            // });
      });
    },
 
 
    // 关闭编辑、增加弹出框
    closeDialog(name) { 
        this.addFormVisible = false; 
        this.$refs.refundForm.resetFields();
    }, 
 
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
/deep/ .el-table .row-expand-cover .cell .el-table__expand-icon {
  display: none;
}
.myForm .el-form-item {
  /* display: inline-block;
  margin-left: 5%; */
}

.el-form .select10 .el-select {
  width: 100%;
}
</style>

 
 